﻿using System;
using System.Globalization;

namespace RIMS.Lib.Utility
{
    internal sealed class OIDGenerator
    {
        /// <summary>
        /// This function genetate a new oid
        /// </summary>
        /// <returns>string</returns>
        public static string GenerateOID(String prefix)
        {
            if (prefix == null)
            {
                RIMSLogger.LogInfo("OID prefix is null");

                return string.Empty;
            }

            if (prefix.Length > 6)
            {
                prefix = prefix.Substring(0, 6);
            }

            //get random number from GUID
            string randomNum = Guid.NewGuid().ToString("N");
            DateTime time = DateTime.Now;

            string oid = String.Format(GetCultureInfo(), "{0}{1}-{2}", prefix, time.ToString("yyyyMMddHHmmss", GetCultureInfo()), randomNum.Substring(0, 12));
            return oid.ToUpper();
        }

        /// <summary>
        /// Get the Culture infor mation
        /// </summary>
        /// <returns>CultureInfo</returns>
        static public CultureInfo GetCultureInfo()
        {

            CultureInfo culture = new CultureInfo("en-US");

            return culture;
        }
    }
}
